package com.nonintrusive.client;

import java.util.ArrayList;

import android.content.ContentResolver;
import android.content.Context;
import android.os.Handler;

import com.nonintrusive.client.database.ClientDB;
import com.nonintrusive.client.tabs.answerquestion.AnswerQuestionAdapter;
import com.nonintrusive.client.tabs.history.HistoryQuestionAdapter;

public class GlobalNonIntrusive {
	public static final String SERVER_IP = "10.0.2.2";
	public static final int PORT = 7777;

	protected static final String ENCODING = "UTF-8";
	public static Integer clientID = -1;
	
	public final static int MAX_ANSWERS = 5;

	public static final int SIMPLE_NOTFICATION_ID = 777;
	
	
	
	// history
	public static ArrayList<Question> allQuestions;
	public static HistoryQuestionAdapter allQAdapter;

	// answer
	public static ArrayList<Question> answerQuestions;
	public static AnswerQuestionAdapter answerQAdapter;

	/**
	 * Removes question (by ID) from all the lists and from DB.
	 * 
	 * @param context
	 * @param question
	 * @param handler
	 */
	public static void removeQID(final Context context,
			final Question question, final Handler handler) {
		new Thread(new Runnable() {
			@Override
			public void run() {
				ContentResolver cr = context.getContentResolver();
				cr.delete(ClientDB.CONTENT_URI, ClientDB.QUESTION_ID + " = "
						+ question.id, null);

				handler.post(new Runnable() {
					@Override
					public void run() {
						allQAdapter.remove(question);
						allQAdapter.notifyDataSetChanged();

						answerQAdapter.remove(question);
						answerQAdapter.notifyDataSetChanged();
					}
				});
			}
		}).start();
	}
}
